package com.example.yls.demoa;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.util.Printer;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {

    private ImageView ivDog;
    private Button btnNext;
    private int[] dogImgs = {R.drawable.dog1, R.drawable.dog1,
            R.drawable.dog2, R.drawable.dog3, R.drawable.dog4};
    private int index = 0;


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ivDog = findViewById(R.id.img_dog);
        btnNext = findViewById(R.id.btn_next);

        btnNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                index = (index + 1) % dogImgs.length;
                ivDog.setImageResource(dogImgs[index]);
            }

        });
    }
}